/*
PearReview - The peer review assistant.
Copyright (C) 2009  Dimitrij Pankratz, Anton Musichin
http://www.pearreview.com, info@pearreview.com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

package com.pearreview.scribeplugin.csv;

import java.io.Serializable;
import java.util.Map;

import com.pearreview.application.Messages;
import com.pearreview.util.review.Finding;
import com.pearreview.util.review.Severity;

public class FindingSeverityColumn implements FindingModelColumnRenderer,
		Serializable {
	private static final long serialVersionUID = -2840209271098652810L;
	public static final String FIELD_NAME = Messages.getString(
			"PearReview.Scribe.findings.severity");
	private Map<Severity, String> severityMap;
	private String name = FIELD_NAME;
	public FindingSeverityColumn() {
		
	}
	public FindingSeverityColumn(Map<Severity, String> severityMap) {
		this.severityMap = severityMap;
	}
	@Override
	public String getColumnName() {
		return name + " [" + FIELD_NAME + "]";
	}
	@Override
	public Severity getValue(Finding finding) {
		return finding.getSeverity();
	}
	@Override
	public Class<?> getValueClass() {
		return Severity.class;
	}
	@Override
	public boolean isEditable() {
		return false;
	}
	@Override
	public void setName(String newName) {
		name = newName;
	}
	@Override
	public String getName() {
		return name;
	}
	@Override
	public void setNewValue(Finding finding, Object newValue) { }
	@Override
	public String getStringValue(Finding finding) {
		Severity severity = finding.getSeverity();
		if(severityMap == null || !severityMap.containsKey(severity)) {
			return severity.getName();
		} else {
			return severityMap.get(severity);
		}
	}
	public void setSeverityMap(Map<Severity, String> severitySet) {
		this.severityMap = severitySet;
	}
	public Map<Severity, String> getSeverityMap() {
		return severityMap;
	}
}